vue
<template>
  <div class="wrapper">
    <!-- 头部区域 -->
    <div class="header-section">
      <!-- 修改 @click 绑定的方法 -->
      <div class="back-btn" @click="goBack"> 
        <i class="fa fa-angle-left" ></i>
      </div>
      <h1 class="login-title">注册</h1>
    </div>

    <!-- 注册表单 -->
    <section class="register-card">
      <div class="card-body">
        <!-- 手机号码 -->
        <div class="input-group">
          <span class="input-icon">
            <i class="fa fa-phone"></i>
          </span>
          <input
            type="text"
            v-model="supervisorForm.telId"
            @blur="isExist"
            placeholder="请输入手机号码"
            class="form-input"
          />
        </div>
        
        <!-- 真实姓名 -->
        <div class="input-group">
          <span class="input-icon">
            <i class="fa fa-user"></i>
          </span>
          <input
            type="text"
            v-model="supervisorForm.realName"
            placeholder="真实姓名便于我们联系您"
            class="form-input"
          />
        </div>
        
        <!-- 出生日期 -->
        <div class="input-group">
          <span class="input-icon">
            <i class="fa fa-calendar"></i>
          </span>
          <input type="date" v-model="supervisorForm.birthday" class="form-input" />
        </div>
        
        <!-- 性别选择 -->
        <div class="radio-group">
          <label class="radio-label">
            <input type="radio" v-model="supervisorForm.sex" value="1" />
            <span class="radio-custom"></span>
            男
          </label>
          <label class="radio-label">
            <input type="radio" v-model="supervisorForm.sex" value="0" />
            <span class="radio-custom"></span>
            女
          </label>
        </div>
        
        <!-- 密码 -->
        <div class="input-group">
          <span class="input-icon">
            <i class="fa fa-lock"></i>
          </span>
          <input
            type="password"
            v-model="supervisorForm.password"
            placeholder="请输入密码"
            class="form-input"
          />
        </div>
        
        <!-- 确认密码 -->
        <div class="input-group">
          <span class="input-icon">
            <i class="fa fa-lock"></i>
          </span>
          <input
            type="password"
            v-model="supervisorForm.confirmPassword"
            placeholder="请再次输入密码"
            class="form-input"
          />
        </div>
        
        <!-- 注册按钮 -->
        <button class="login-btn" @click="register">
          注册
        </button>
      </div>
    </section>
    
    <!-- 底部信息 -->
    <footer class="app-footer">
      <p class="footer-copyright">© 2025 东软环保公众监督系统 版权所有</p>
      <p class="footer-contact">技术支持: 400-888-8888</p>
    </footer>
  </div>
</template>


<script setup>
import { reactive, inject } from "vue";
import { useRouter } from "vue-router";

const router = useRouter();
const axios = inject("axios");

const supervisorForm = reactive({
  telId: '',
  realName: '',
  birthday: '',
  sex: 1,
  password: '',
  confirmPassword: ''
});

const isExist = ()=>{
  axios
    .post("supervisor/getSupervisorById", supervisorForm)
    .then((response)=>{
      if(response.data!=''){
        alert('此手机号码已被注册！');
        supervisorForm.telId = '';
      }
    })
    .catch((error)=>{
      console.log(error);
    });
}

const register = ()=>{
  //表单验证
  if (supervisorForm.telId == "") {
    alert("电话号码不能为空！");
    return;
  }
  if (supervisorForm.telId.length != 11) {
    alert("电话号码必须为11位长度！");
    return;
  }
  if (isNaN(supervisorForm.telId)) {
    alert("电话号码必须由数字组成！");
    return;
  }
  if (supervisorForm.realName == "") {
    alert("真实姓名不能为空！");
    return;
  }
  if (supervisorForm.birthday == "") {
    alert("出生日期不能为空！");
    return;
  }
  if (supervisorForm.password == "") {
    alert("密码不能为空！");
    return;
  }
  if (supervisorForm.password != supervisorForm.confirmPassword) {
    alert("两次密码输入不一致！");
    return;
  }
  
  axios
    .post("supervisor/saveSupervisor", supervisorForm)
    .then((response)=>{
      if(response.data==1){
        alert('注册成功！');
        router.push('/login');
      }else{
        alert('注册失败！');
      }
    })
    .catch((error)=>{
      console.log(error);
    });
}

</script>

<script>
export default {
  data() {
    return {
      supervisorForm: {
        telId: '',
        realName: '',
        birthday: '',
        sex: '1',
        password: '',
        confirmPassword: ''
      }
    }
  },
  methods: {
    isExist() {
      // 检查手机号是否存在的逻辑
    },
    register() {
      // 注册逻辑
    },
    // 新增：返回登录页的方法
    goBack() {
      this.$router.push('/login') // 跳转到登录页路由
    }
  }
}
</script>

<style scoped>
/* 页面布局 */
.wrapper {
  min-height: 100vh;                  
  /* 替换为背景图配置 */
  background: url('../assets/hjbh.jpg') no-repeat center center / cover; 
  font-family: 'PingFang SC', sans-serif;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  padding: 0 20px;
  min-height: 100vh;
  max-width: 428px; /* 限制最大宽度为常见手机尺寸（如 iPhone 14 Pro Max 宽度） */
  margin: 0 auto;
  /* 若之前有 max-width 等限制，保持不变 */
}
/* 头部样式 */
.header-section {
  width: 100%;
  text-align: center;
  margin-bottom: 30px;
  position: relative;
}
.back-btn {
  position: absolute;
  left: 0;
  top: 0;
  width: 40px;
  height: 40px;
  background: rgba(0,0,0,0.1);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.back-btn i {
  color: #333;
  font-size: 20px;
}
.login-title {
  font-size: 40px;
  font-weight: 600;
  margin: 0;
  
  color: #333;
  background: linear-gradient(135deg, #000000 0%, #e6e6e6 100%);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  
  text-shadow: 
    1px 1px 1px rgba(255, 255, 255, 0.8),
    -1px -1px 1px rgba(0, 0, 0, 0.2);
}
.header-decoration {
  width: 60px;
  height: 3px;
  background: #000;
  margin: 10px auto 0;
  border-radius: 3px;
}

/* 注册卡片 */
.register-card {
  width: 100%;
  max-width: 360px;
  background: rgba(255,255,255,0.9);
  border-radius: 16px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.08);
  padding: 40px;
}

/* 输入组样式 */
.input-group {
  display: flex;
  align-items: center;
  margin-bottom: 24px;
  border-bottom: 1px solid #e5e5e5;
  padding-bottom: 8px;
}
.input-icon {
  color: #999;
  font-size: 16px;
  margin-right: 12px;
}
.form-input {
  flex: 1;
  border: none;
  outline: none;
  background: transparent;
  font-size: 14px;
  color: #333;
}

/* 单选按钮样式 */
.radio-group {
  display: flex;
  gap: 30px;
  margin: 15px 0 25px;
}
.radio-label {
  display: flex;
  align-items: center;
  cursor: pointer;
  font-size: 14px;
}
.radio-custom {
  width: 16px;
  height: 16px;
  border: 1px solid #ccc;
  border-radius: 50%;
  margin-right: 8px;
  position: relative;
}
.radio-label input:checked + .radio-custom {
  border-color: #000;
}
.radio-label input:checked + .radio-custom::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 8px;
  height: 8px;
  background: #000;
  border-radius: 50%;
}
.radio-label input {
  display: none;
}

/* 注册按钮 */
.login-btn {
  width: 100%;
  padding: 12px;
  background: #000;
  color: #fff;
  border: none;
  border-radius: 25px;
  font-size: 16px;
  cursor: pointer;
  transition: background 0.3s;
}
.login-btn:hover {
  background: #333;
}

/* 底部信息 */
.app-footer {
  text-align: center;
  color: #666;
  margin-top: 30px;
  font-size: 12px;
}
.app-footer p {
  margin: 5px 0;
}
</style>